import { SYSTEM_SHOW_LOADING, SYSTEM_HIDE_LOADING } from '../actions/systemLoading';
import createReducer from '../../utils/createReducer.js';

const initialState = {
  loading: false,
  loadingText: ''
};

const handlers = {
  [SYSTEM_SHOW_LOADING](state, { payload = { text: '' } }) {
    const { text } = payload;

    return {
      loading: true,
      loadingText: text
    };
  },

  [SYSTEM_HIDE_LOADING](state) {
    return {
      loading: false,
      loadingText: ''
    };
  }
};

export default createReducer(initialState, handlers);
